package Queue;
import java.util.*;
public class MyQueue {
    private final Stack<Integer> stack1;    //用来push的栈
    private final Stack<Integer> stack2;    //用来pop的栈
    public MyQueue() {
        stack1=new Stack<>();
        stack2=new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if(empty()) {
            return -1;
        }
        if(stack2.isEmpty()) {              //如果一开始pop栈为空，那么就放数据
            while(!stack1.isEmpty()) {
                int x=stack1.pop();
                stack2.push(x);
            }
        }
        int val=stack2.peek();
        stack2.pop();
        return val;
    }

    public int peek() {
        if(stack2.isEmpty()) {              //如果一开始pop栈为空，那么就放数据
            while(!stack1.isEmpty()) {
                int x=stack1.pop();
                stack2.push(x);
            }
        }
        return stack2.peek();
    }

    public boolean empty() {
        return stack1.isEmpty()&&stack2.isEmpty();
    }
}
